import input from '../module/input.mjs'
import todolistObj from '../module/toDoList.mjs'
import doneList from '../module/doneList.mjs'


export default new Vue({
    el: "#app",
    data: {
        // v-model的双向绑定获取input标签中的内容
        msg: "",
        // 输入的索引
        indexList: 0,

        indexDoneList:0,
        // 存储未办内容input每次输入的内容
        list: [],
        // 存储已办内容
        doneList: [],

    },
    // 生命周期
    created() {
        // 进行判断 如果为空是不赋值给list
        this.list = JSON.parse(localStorage.getItem("list")) || [];
        this.doneList = JSON.parse(localStorage.getItem("doneList")) || [];

        
    },

    updated() {
        localStorage.setItem("list", JSON.stringify(this.list));
        localStorage.setItem("doneList", JSON.stringify(this.doneList));

        this.indexList = this.list.length;
        this.indexDoneList = this.doneList.length;

    },
    components:{
        "input-top":input,
        "todo-list":todolistObj,
        "done-list":doneList
    },


    methods: {
        btnClick(e) {
            console.log(e);
            let message = this.msg.trim();
            // 判断输入内容不为空
            if (message) {
                if (this.list.indexOf(message) > -1) {
                    alert("您输入的事项已存在")
                } else {
                    this.list.push(message);
                    this.index++;
                }
            } else {
                alert("您输入的事项为空");
            }
            this.msg = "";
        },

        selClick(index){
       
            let it = this.list.splice(index,1);
            this.doneList.push(it.toString())
        },

        delClick(index){
            this.list.splice(index,1);
        },
      

        del1Click(index){
            console.log(index);
            this.doneList.splice(index,1);
        },

    },

});
